<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h3>{{ bookShop }}</h3>
        <ul>
            <li v-for = 'item in books'>编号:{{item.id}} 书名: {{item.name}} 价格: {{item.price}}</li>
        </ul>
        <h2>总价格: {{totalPrice}}</h2>
    </div>
    <script src='../js/vue.js'></script>
    <script>
        const app = new Vue({
            el: '#app',
            data:{
                firstName:'重庆',
                lastName:'新华书店',
                books:[
                    {id: 1001, name:'C语言', price: 123},
                    {id: 1002, name:'JavaScript', price: 46},
                    {id: 1003, name:'Python', price: 78},
                    {id: 1004, name:'Java', price: 42},
                    {id: 1004, name:'C#', price: 75},
                ]
            },
            computed:{
                bookShop: function(){
                    return this.firstName + ' ' + this.lastName;
                },
                totalPrice: function() {
                    let result = 0;
                    for(let book of this.books) {
                        console.log(book);
                        result += book.price
                    }
                    return result;  
                }
            }
        })
    </script>
</body>

</html>